//
// Created by ASUS on 2024/10/16/星期三.
//
#include <bits/stdc++.h>
using namespace std;

vector<int> queryKind(vector<int>&nums,vector<vector<int>>&queries){
	int n=nums.size(),m=queries.size();
	nums.insert(nums.begin(),0);
	vector<int> ans(m);
	unordered_map<int,int> cnt;
	int  len = max(1, (int)sqrt((double)n * n / m));
	//根据原数组下标获取分块的下标
	auto get=[&](int x){
		return x/len;
	};

	auto add=[&](int x, int& res){
		if (!cnt[x]) res ++ ;
		cnt[x] ++ ;
	};

	auto del=[&](int x, int& res){
		cnt[x] -- ;
		if (!cnt[x]) res -- ;
	};

	vector<int> idx(m);
	iota(idx.begin(), idx.end(), 0);
	ranges::sort(idx, [&](int i, int j) {
		int a=get(queries[i][0]),b=get(queries[j][0]);
		if(a!=b) return a<b;
		return queries[i][1]<queries[j][1];
	});
	for (int k = 0, r = 0, l = 1, res = 0; k < m; k ++ )
	{
		int  ql = queries[idx[k]][0], qr = queries[idx[k]][1];
		while (ql<l) add(nums[--l], res);
		while (qr>r) add(nums[++r], res);
		while (ql>l) del(nums[l++], res);
		while (qr<r) del(nums[r--], res);
		ans[k] = res;
	}
	return ans;
}